using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

using DataTransferObject;
using Business;
namespace Presentation.UserControlls
{
    public partial class UC_SachTraTre : UserControl
    {
        clsThuThuBUS ThuThuBUS = new clsThuThuBUS();
        clsThayDoiQuyDinhBUS TDQuyDinhBUS = new clsThayDoiQuyDinhBUS();
        DataTable tbl = new DataTable();
        int tongcong;
        int QuyDinhsongaymuon;


        public UC_SachTraTre()
        {
            InitializeComponent();
        }

        private void UC_SachTraTre_Load(object sender, EventArgs e)
        {
            dtngay.Text = Convert.ToString(DateTime.Now.ToShortDateString());

            tbl = TDQuyDinhBUS.DanhSachThayDoiQuyDinh();
            foreach (DataRow dr in tbl.Rows)
            {
                QuyDinhsongaymuon  = Convert.ToInt32(dr["SoNgayMuonToiDa"].ToString());
            }

            HienThiListView();
            lbltongcong.Text = Convert.ToString(tongcong);
           

        }

        private void HienThiListView()
        {
            tbl = ThuThuBUS.CTMuonTraBUS.ThongKeSachTraTre();
            foreach (DataRow dr1 in tbl.Rows)
            {
                DateTime ngaymuon = DateTime.Parse(dr1["NgayMuon"].ToString());
                int songaymuon = Convert.ToInt32(((TimeSpan)(DateTime.Now - ngaymuon)).Days.ToString());
                int songaytre = 0;
                if (songaymuon > QuyDinhsongaymuon)
                {
                    tongcong = tongcong + 1;
                    songaytre = songaymuon - QuyDinhsongaymuon;
                    ListViewItem lvwitem = new ListViewItem();
                    lvwthongkesachtre.Items.Clear();
                    lvwitem.Text = dr1["DKCB"].ToString();
                    lvwitem.SubItems.Add(dr1["TenTuaSach"].ToString());

                    lvwitem.SubItems.Add(ngaymuon.ToString());
                    lvwitem.SubItems.Add(songaytre.ToString());


                    lvwthongkesachtre.Items.Add(lvwitem);

                }


            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            DialogResult dlg = new DialogResult();
            dlg = DevComponents.DotNetBar.MessageBoxEx.Show("Bạn có muốn thoát không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dlg == DialogResult.Yes)
            {
                this.ParentForm.Close();

            }
        }

        private void btnIn_Click(object sender, EventArgs e)
        {
            FromInAn.FrmThongKeSachTraTre TKSachTraTre = new Presentation.FromInAn.FrmThongKeSachTraTre();
            TKSachTraTre.Show();
        }

        
    }
}
